package com.crm.service.impl;

import com.crm.mapper.IndexMapper;
import com.crm.service.IndexService;
import com.crm.vo.BaseInfoVo;
import com.crm.vo.VulnerabilityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class IndexServiceImpl implements IndexService {
    @Autowired
    IndexMapper indexMapper;

    @Override
    public BaseInfoVo getJCDate(LocalDate beginCreateTime,LocalDate endCreateTime) {
        BaseInfoVo baseInfoVo = new BaseInfoVo();
        Integer clueJC = indexMapper.getClueJC(beginCreateTime,endCreateTime);
        if (clueJC != null){
            baseInfoVo.setCluesNum(clueJC);
        }
        Integer BusinessJC = indexMapper.getBusinessJC(beginCreateTime,endCreateTime);
        if (BusinessJC != null){
            baseInfoVo.setBusinessNum(BusinessJC);
        }
        Integer businessContract = indexMapper.getBusinessContract(beginCreateTime, endCreateTime);
        if (businessContract != null){
            baseInfoVo.setContractNum(businessContract);
        }
        return baseInfoVo;
    }

    @Override
    public VulnerabilityVo getLDDate(LocalDate beginCreateTime, LocalDate endCreateTime) {
        VulnerabilityVo vulnerabilityVo = new VulnerabilityVo();
        Integer sumClue = indexMapper.getSumClue(beginCreateTime, endCreateTime);//线索总数
        Integer yesClue = indexMapper.getYESClue(beginCreateTime, endCreateTime);//有效线索
        Integer business = indexMapper.getBusiness(beginCreateTime, endCreateTime);//转商机数
        Integer contract = indexMapper.getContract(beginCreateTime, endCreateTime);//转为客户数
        if (sumClue != null && business != null) {
            vulnerabilityVo.setCluesNums(sumClue+business);
        }
        if (yesClue != null) {
            vulnerabilityVo.setEffectiveCluesNums(yesClue+business);
        }
        if (business != null) {
            vulnerabilityVo.setBusinessNums(business);
        }
        if (contract != null) {
            vulnerabilityVo.setContractNums(contract);
        }
        return vulnerabilityVo;
    }
}
